package com.sq.partner.manager.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;

import com.sq.partner.manager.common.Constants;
import com.sq.partner.manager.common.exception.AppException;
import com.sq.partner.manager.dao.IGatewayAgentInfoMtDao;
import com.sq.partner.manager.mybatis.model.GatewayUser;
import com.sq.partner.manager.mybatis.model.TradAgentInfo;
import com.sq.partner.manager.mybatis.model.TradSaleAgent;
import com.sq.partner.manager.util.DBMap;
import com.sq.partner.manager.util.DBUtil;
import com.sq.partner.manager.util.LogUtil;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.SqlUtil;
import com.sq.partner.manager.util.StrUtil;
import com.ctc.wstx.util.StringUtil;
/**
 * 
 * @author zzguo
 *
 */
@Repository
public class IGatewayAgentInfoMtDaoImpl extends BaseDaoImpl implements IGatewayAgentInfoMtDao {
	
	private static Logger logger = LogUtil.getLog(IGatewayAgentInfoMtDaoImpl.class);
	
	@Override
	public Page<TradAgentInfo> queryInfoByCriteria(Page<TradAgentInfo> page,GatewayUser user) throws Exception {
		Connection conn = null;
		PreparedStatement pstmt = null;
		PreparedStatement pstmt1 = null;
		ResultSet rs = null;
		try {
			String deptStr = user.getDepartmentStr();
			/*String str=user.getDepartmentStr();
			String userDept="";
			if(StrUtil.isNotEmpty(str)){
				String[] depts= str.split(",");
				for (String string : depts) {
					userDept+=" union select  "+ string+ " from dual";
				}
			}*/
			if(StrUtil.isNotEmpty(deptStr)){
				StringBuilder sql = new StringBuilder();
				sql.append(" SELECT T.ID,T.AGENT_TYPE, "+
				"        T1.CODE_NAME,                            "+
				"        T.USER_CODE,                         "+
				"        T3.USER_NAME,                            "+
				"        T.CHANNEL_CODE,                          "+
				"        T2.CHANNEL_NAME,                         "+
				"        T.SUB_CHANNEL_CODE,                      "+
				"        T4.BRANCH_NAME,                     "+
				"        T.DPT_CDE,                               "+
				"        T.CHANNLE_CODE CHANNLECODE,			"+
				"        D1.CODE_NAME AS CHANNLECODEDES, 	"+
				"        T.CHANNLE_TYPE AS CHANNLETYPE,         	"+
				"        D2.CODE_NAME AS CHANNLETYPEDES, 	"+
				"        T.NEW_BSNS_TYPE AS NEWBSNSTYPE,         	"+
				"        D3.CODE_NAME AS NEWBSNSTYPEDES, 	"+
				"        T.CATEGORY_CODE AS CATEGORYCODE,        	"+
				"        D4.CODE_NAME AS CATEGORYCODEDES,	"+
				"        T.AGENT_NO,                              "+
				"        T.PROTOCOL_NO,                           "+
				"        T.SERVICE_CODE,                          "+
				"        T.ORG_CODE,                          "+
				"        T.EMP_NO,T.CARD_APPLICANT,"+
				"        T.TEAM_CODE,T.TEAM_NAME,T.C_BRKR_NME,T.C_OPR_CDE,T.SERVICE_NAME,T.EMP_NAME,T.key1,T.key2,T.key3,T.key4,T.key5,T.UNION_TYPE, "+ 
				"		 T.MANAG_CODE,T.MANAG, "+ 
				"		 d5.Code_Name UNION_NAME,T4.ZONE,T4.BRANCH,T2.TRANS_TYPE,"+
						"T.C_AGENCY_CDE,"+
						"T.C_PTCC_NUMBER,"+
						"T.C_PHONE,"+
						"T.C_EMPLO_YEE,"+
						"T.C_BRKR_CERTF_CDE,"+
						"C_SLS_IDENTITY_NO"+
				"   FROM T_TRAD_AGENT_INFO T                      "+
				"  INNER JOIN T_GATEWAY_DICT T1                   "+
				"     ON T.AGENT_TYPE = T1.CODE                   "+
				"    AND T1.CODE_TYPE = 'agent_type'              "+
				"  LEFT JOIN T_GATEWAY_CHANNEL_INFO T2           "+
				"     ON T.CHANNEL_CODE = T2.CHANNEL_CODE         "+
				"    AND T2.STATUS = '1'                          ");
				sql.append("   LEFT JOIN T_FACADE_USER T3                    "+
				"     ON T.USER_CODE = T3.USER_CODE  AND T3.USER_TYPE IN ('3', '4') "+
				"   LEFT JOIN T_GATEWAY_SUB_CHANNEL T4            "+
				"     ON T.SUB_CHANNEL_CODE = T4.SUB_CHANNEL_CODE AND T.AGENT_TYPE = '4'  AND T.CHANNEL_CODE=T4.FK_CHANNEL_CODE");
				sql.append("  LEFT JOIN t_gateway_dict d1 on d1.code_type ='belong_to_channel' and T.CHANNLE_CODE = d1.code ")
				.append(" LEFT JOIN t_gateway_dict d2 on d2.code_type ='channel_type' and T.Channle_Type = d2.code ")
				.append(" LEFT JOIN t_gateway_dict d3 on d3.code_type ='new_business_source' and T.New_Bsns_Type = d3.code ")
				.append(" LEFT JOIN t_gateway_dict d4 on d4.code_type ='old_business_source' and T.Category_Code = d4.code ")
				.append(" LEFT JOIN t_gateway_dict d5 on d5.code_type = 'union_type'  and T.UNION_TYPE = d5.code")
				.append(" where 1=1 ");
			List<String> params = new ArrayList<String>();
			if (StrUtil.isNotEmpty(page.getType().getAgentType())) {
				sql.append(" AND  T.AGENT_TYPE = ? ");
				params.add(page.getType().getAgentType());
				/*if(!deptStr.contains(Constants.HQ_BRANCH_CODE)&&!"5".equals(page.getType().getAgentType())){
					sql.append(" AND T2.DEPT_CODE IN (SELECT DEPT_CODE FROM T_CORE_DEPT WHERE DEPT_CODE LIKE '00%' "+userDept+")");
				}*/
				if(!deptStr.contains(Constants.HQ_BRANCH_CODE) ){//&& !"5".equals(page.getType().getAgentType())
					sql.append(" AND T.DPT_CDE IN (SELECT DEPT_CODE FROM T_CORE_DEPT WHERE DEPT_CODE LIKE ? ) ");
					params.add(deptStr.substring(1, 3)+"%");
				}
			}
			if (StrUtil.isNotEmpty(page.getType().getChannelCode())) {
				sql.append(" AND T.CHANNEL_CODE = ? ");
				params.add(page.getType().getChannelCode());
				if("4".equals(page.getType().getAgentType())){
					sql.append(" AND T4.fk_channel_code = ? ");
					params.add(page.getType().getChannelCode());
				}
			}
			if (StrUtil.isNotEmpty(page.getType().getUserName())) {
				String userName = page.getType().getUserName();
				String userNameStr = "%" + userName + "%";
				sql.append(" AND T3.USER_NAME like ? ");
				params.add(userNameStr);
			}
			if (StrUtil.isNotEmpty(page.getType().getUserCode())) {
				String userCode = page.getType().getUserCode();
				String userCodeStr = "%" + userCode + "%";
				sql.append(" AND T.USER_CODE  like ? ");
				params.add(userCodeStr);
			}
			/**网点代码*/
			if(StrUtil.isNotEmpty(page.getType().getBranch())){
				String branch=page.getType().getBranch();
				sql.append(" and T4.Sub_Channel_Code LIKE ? ");
				params.add("%"+branch+"%");
			}
			/**网点名称**/
			if(StrUtil.isNotEmpty(page.getType().getBranchName())){
				String branchName=page.getType().getBranchName();
				String branchNameStr = "%" + branchName + "%";
				sql.append("  and  T4.Sub_Channel_Name like ? ");
				params.add(branchNameStr);
			}
			/**业务员代码**/
			if(StrUtil.isNotEmpty(page.getType().getEmpNo())){
				String empNo=page.getType().getEmpNo();
				sql.append("  and  T.Emp_No LIKE  ? ");
				params.add("%"+empNo+"%");
			}
			/**机构代码代码**/
			if(StrUtil.isNotEmpty(page.getType().getDptCde())){
				String deptCode=page.getType().getDptCde();
				sql.append("  and  T.DPT_CDE LIKE ? ");
				params.add(deptCode+"%");
			}
			/**代理人编码**/
			if(StrUtil.isNotEmpty(page.getType().getAgentNo())){
				String agentNo=page.getType().getAgentNo();
				sql.append("  and  T.AGENT_NO LIKE ? ");
				params.add("%"+agentNo+"%");
			}
			/**代理协议号**/
			if(StrUtil.isNotEmpty(page.getType().getProtocolNo())){
				String protocalNo=page.getType().getProtocolNo();
				sql.append("  and  T.PROTOCOL_NO LIKE ? ");
				params.add("%"+protocalNo+"%");
			}
			/**业务员名称**/
			if(StrUtil.isNotEmpty(page.getType().getEmpName())){
				String empName = page.getType().getEmpName();
				sql.append(" and  T.EMP_NAME LIKE ? ");
				params.add("%"+empName+"%");
			}
			/**经办人代码**/
			if(StrUtil.isNotEmpty(page.getType().getManag())){
				String manag = page.getType().getManag();
				sql.append(" and  T.MANAG LIKE ? ");
				params.add("%"+manag+"%");
			}
			sql.append(" ORDER BY t.oper_time DESC,T.ID DESC ");
			conn = this.getConnection();
			Long total = 0L;
			logger.debug("excute :sql-->    "+sql.toString());
			pstmt = conn.prepareStatement("select count(*) from ("+ sql.toString() + ")");
			for (int i = 0; i < params.size(); i++) {
				pstmt.setObject(i + 1, params.get(i));
			}
			rs = pstmt.executeQuery();
			if (rs.next()) {
				total = rs.getLong(1);
			}
			page.setTotal(total);

			SqlUtil sqlUtil = new SqlUtil();

			String sqlPage = sqlUtil.buildPageSqlForOracle(sql.toString(),page).toString();

			pstmt1 = conn.prepareStatement(sqlPage);
			for (int i = 0; i < params.size(); i++) {
				pstmt1.setObject(i + 1, params.get(i));
			}
			rs = pstmt1.executeQuery();
			List dataList = DBUtil.transRs2List(rs);
			
			page.setData(dataList);
			}
		} finally {
			close(pstmt);
			close(pstmt1);
			close(rs);
			close(conn);
		}
		return page;
	}

	@Override
	public boolean addAgentInfo(TradAgentInfo agent) throws Exception {
		return this.add("insertTradAgentInfo", agent);
	}

	@Override
	public boolean updateAgentInfo(TradAgentInfo agent) throws Exception {
		return this.update("updateTradAgentInfoNotNull", agent);
	}

	@Override
	public TradAgentInfo queryAgentInfoByCode(TradAgentInfo agent) throws Exception {
		List<TradAgentInfo> ls= (List<TradAgentInfo>) this.query("queryGatewayAgentByUserCodeAndAgentType", agent);
		if(ls!=null&&!ls.isEmpty()){
			return ls.get(0);
		}else{
			return null;
		}
	}

	@Override
	public boolean deleteAgentInfo(TradAgentInfo agent) throws Exception {
		return this.delete("delTradAgentInfoById", agent.getId());
	}

	@Override
	public int checkIsExistConfigPlanInfo(Long agentId) throws Exception {
		return (Integer) this.query("queryRecordCountByAgentId", agentId);
	}

	@Override
	public List<TradAgentInfo> searchExistUserCodeInfoFromDB(String str) throws AppException {
		try {
			return this.queryList("queryExistUserCodeInfoFromDB", str.substring(0, str.length()-1));
		} catch (SQLException e) {
			logger.error(e);
			throw new AppException("数据库应用忙，请稍后重试！");
		}
	}

	@Override
	public List<TradAgentInfo> searchExistChannelInfoFromDB(String str) throws AppException {
		try {
			if("'00'".equals(str)){//总公司
				return this.queryList("queryExistChannelInfoFromDB", str);
			}else{//分公司
				return this.queryList("queryExistChannelInfoFromDB1", "'"+str.substring(1,3)+"%'");
			}
		} catch (SQLException e) {
			logger.error(e);
			throw new AppException("数据库应用忙，请稍后重试！");
		}
	}

	@Override
	public void addBatchAgentInfo(List<TradAgentInfo> list) throws AppException {
		if(null!=list && list.size()> 0){
			try {
				this.add("insertBatchTradAgentInfoList", list);
			} catch (Exception e) {
				logger.error(e);
				throw new AppException("数据库应用忙，请稍后重试！");
			}
		}
	}

	@Override
	public List<TradAgentInfo> searchExistSubBranchCodeInfoFromDB(Map<String, String> map) throws AppException {
		try {
			 return this.queryList("queryExistSubBranchCodeInfoFromDB", map);
		} catch (SQLException e) {
			logger.error(e);
			throw new AppException("数据库应用忙，请稍后重试！");
		}
	}

	@Override
	public Page<Map<String, Object>> queryAgentInfoWithUserPageByCriteria(
			Page<Map<String, Object>> page) throws Exception {
		Connection conn = null;
		//查总条数
		PreparedStatement pstmt = null;
		//查分页
		PreparedStatement pstmt1 = null;
		ResultSet rs = null;
		try{
			conn = this.getConnection();
			StringBuffer sqlbuf=new StringBuffer();
			sqlbuf.append(" select t.id, t.user_code, u.user_name, t.dpt_cde, t.service_code,t.service_name,t.C_BRKR_NME,t.C_OPR_CDE,t.emp_no,t.emp_name,t.card_applicant, t.team_code, ")
		          .append(" d1.code_name as channlecodedes,d2.code_name as channletypedes,d3.code_name as newbsnstypedes, t.agent_no, t.protocol_no")
		          .append("  , rela.insu_plan_no as planNO from T_TRAD_AGENT_INFO t  ")
		          .append(" left join T_FACADE_USER u on t.user_code = u.user_code ")
		          .append(" left join T_GATEWAY_DICT d1 on d1.code_type ='belong_to_channel' and t.channle_code = d1.code ")
			      .append(" left join T_GATEWAY_DICT d2 on d2.code_type ='channel_type' and t.channle_type = d2.code ")
				  .append(" left join T_GATEWAY_DICT d3 on d3.code_type ='new_business_source' and t.new_bsns_type = d3.code ")
				  .append(" left join T_TRAD_AGENT_INFO_RELA rela  on t.id=rela.agent_info_id   and  rela.insu_plan_no='"+page.getMap().get("planNo")+"'")
				  .append(" WHERE 1=1 ");
						
			String sql;
			List<String> list=new ArrayList<String>();
			List<Boolean> islike=new ArrayList<Boolean>();
			Map<String,Object> paramMap = page.getMap();
			
			String channelCode =StrUtil.getVal(paramMap.get("partnerNo"));
			if(StrUtil.isNotEmpty(channelCode)){
				sqlbuf.append(" and t.channel_code = ?");
				list.add(channelCode);
				islike.add(false);
			}
			
			String agentType =StrUtil.getVal(paramMap.get("agentType"));
			if(StrUtil.isNotEmpty(agentType)){
				sqlbuf.append(" and t.agent_type = ?");
				list.add(agentType);
				islike.add(false);
			}
			String dept_code = StrUtil.getVal(paramMap.get("dept_code"));
			if(StrUtil.isNotEmpty(dept_code) && !"00".equals(dept_code)){
			  sqlbuf.append(" and t.dpt_cde like ?");
			  list.add(dept_code+"%");
			  islike.add(false);
			}else if(StrUtil.isNotEmpty(dept_code) && "00".equals(dept_code)){
				sqlbuf.append(" and t.dpt_cde in (select dept_code from t_core_dept t connect by prior dept_code = snr_dept start with dept_code in ( ? ))");
				list.add(dept_code);
				islike.add(false);
			}
			/*sqlbuf.append("ORDER BY planNO ");*/
			sql=sqlbuf.toString();
			
			String confStatus = StrUtil.getVal(paramMap.get("confStatus"));
			if("Y".equals(confStatus)){
				sql ="SELECT * FROM ("+sql+") A WHERE  exists (SELECT 1 FROM T_TRAD_AGENT_INFO_RELA R  where R.Insu_Plan_No=? and R.AGENT_INFO_ID= A.ID ) ";
				String planNo = StrUtil.getVal(paramMap.get("planNo"));
				if(StrUtil.isNotEmpty(planNo)){
					list.add(planNo);
					islike.add(false);
				}
			}else if("N".equals(confStatus)){
				sql ="SELECT * FROM ("+sql+") A WHERE not exists (SELECT 1 FROM T_TRAD_AGENT_INFO_RELA R  where R.Insu_Plan_No=? and R.AGENT_INFO_ID= A.ID ) ";
				String planNo = StrUtil.getVal(paramMap.get("planNo"));
				if(StrUtil.isNotEmpty(planNo)){
					list.add(planNo);
					islike.add(false);
				}
			}else{
				sql = "SELECT * FROM ("+sql+") A WHERE 1=1 ";
			}
			
			String userCode =StrUtil.getVal(paramMap.get("userCode"));
			if(StrUtil.isNotEmpty(userCode)){
				sql = sql +" and A.user_code like ? ";
				list.add(userCode);
				islike.add(true);
			}
			
			String userName =StrUtil.getVal(paramMap.get("userName"));
			if(StrUtil.isNotEmpty(userName)){
				sql = sql +" and A.user_name like ? ";
				list.add(userName);
				islike.add(true);
			}
			
		/*	sql = sql +" ORDER BY A.user_code ";*/
			sql = sql +" ORDER BY planNO ,A.user_code ";
			logger.debug("执行SQL：" + sql);

			pstmt = conn.prepareStatement("select count(*) from ("+sql+")");
			for (int i = 0; i < list.size(); i++) {
				if(islike.get(i)){
					pstmt.setObject(i+1, "%"+list.get(i)+"%");
				}else{
					pstmt.setObject(i+1, list.get(i));
				}
			}
			rs = pstmt.executeQuery();
			rs.next();
			Long total = rs.getLong(1);
			page.setTotal(total);
			//查出分页
			SqlUtil sqlUtil=new	SqlUtil();
			String pagesql=sqlUtil.buildPageSqlForOracle(sql,page).toString();
			logger.debug("执行SQL："+pagesql);
			pstmt1 = conn.prepareStatement(pagesql);
			for (int i = 0; i < list.size(); i++) {
				if(islike.get(i)){
					pstmt1.setObject(i+1, "%"+list.get(i)+"%");
				}else{
					pstmt1.setObject(i+1, list.get(i));
				}
			}
			rs = pstmt1.executeQuery();
			List resultList = DBUtil.transRs2List(rs);
			page.setData(resultList);
		}finally{
			close(rs);
			close(pstmt);
			close(pstmt1);
			close(conn);
		}

		return page;
	}

	@Override
	public Page<Map<String, Object>> queryAgentInfoWithChannelPageByCriteria(
			Page<Map<String, Object>> page) throws Exception {
		Connection conn = null;
		//查总条数
		PreparedStatement pstmt = null;
		//查分页
		PreparedStatement pstmt1 = null;
		ResultSet rs = null;
		try{
			conn = this.getConnection();
			StringBuffer sqlbuf=new StringBuffer();
			sqlbuf.append(" select t.id, t.channel_code,t.sub_channel_code,sc.branch,sc.branch_name,sc.zone,t.dpt_cde, t.service_code,t.C_BRKR_NME,t.C_OPR_CDE,t.service_name,t.emp_no,t.emp_name, t.card_applicant,")
				   .append(" t.team_code,core.dept_cname,d1.code_name as channlecodedes,d2.code_name as channletypedes,d3.code_name as newbsnstypedes,t.agent_no,t.protocol_no, ")
				   .append(" CI.TRANS_TYPE AS TRANSTYPE,U.FK_SUB_CHANNEL_CODE AS FKSUBCHANNELCODE ,U.USER_CODE AS USERCODE , U.USER_NAME AS USERNAME ")
				   .append(" , rela.insu_plan_no as planNO  from T_TRAD_AGENT_INFO t  ")
				   .append(" left join T_GATEWAY_SUB_CHANNEL sc on t.sub_channel_code =sc.sub_channel_code")
				   .append(" LEFT JOIN T_FACADE_USER U on  SC.SUB_CHANNEL_CODE=U.FK_SUB_CHANNEL_CODE AND U.USER_CODE=t.USER_CODE  ")
				   .append(" LEFT JOIN T_GATEWAY_CHANNEL_INFO CI ON SC.PARENT_CHANNEL_CODE =CI.CHANNEL_CODE ")
				   .append(" left join T_GATEWAY_DICT d1 on d1.code_type ='belong_to_channel' and t.channle_code = d1.code ")
			       .append(" left join T_GATEWAY_DICT d2 on d2.code_type ='channel_type' and t.channle_type = d2.code ")
				   .append(" left join T_GATEWAY_DICT d3 on d3.code_type ='new_business_source' and t.new_bsns_type = d3.code ")
				   .append(" left join t_core_dept core on t.dpt_cde = core.dept_code")
				   .append(" left join T_TRAD_AGENT_INFO_RELA rela  on t.id=rela.agent_info_id   and  rela.insu_plan_no='"+page.getMap().get("planNo")+"'")
				   .append(" WHERE 1=1 ");

			String sql;
			List<String> list=new ArrayList<String>();
			List<Boolean> islike=new ArrayList<Boolean>();
			Map<String,Object> paramMap = page.getMap();
			
			String channelCode =StrUtil.getVal(paramMap.get("partnerNo"));
			if(StrUtil.isNotEmpty(channelCode)){
				sqlbuf.append(" and t.channel_code = ?");
				list.add(channelCode);
				islike.add(false);
				sqlbuf.append("  and SC.fk_channel_code=?");
				list.add(channelCode);
				islike.add(false);
			}
			String agentType =StrUtil.getVal(paramMap.get("agentType"));
			if(StrUtil.isNotEmpty(agentType)){
				sqlbuf.append(" and t.agent_type= ?");
				list.add(agentType);
				islike.add(false);
			}
			String dept_code = StrUtil.getVal(paramMap.get("dept_code4"));
			/*if(StrUtil.isNotEmpty(dept_code) && !"00".equals(dept_code)){
			  sqlbuf.append(" and t.dpt_cde in  (select dept_code from t_core_dept t connect by prior dept_code = snr_dept start with dept_code in ( ? ))");
			  list.add(dept_code+"%");
			  islike.add(false);
			}else if(StrUtil.isNotEmpty(dept_code) && "00".equals(dept_code)){*/
			sqlbuf.append(" and t.dpt_cde in (select dept_code from t_core_dept t connect by prior dept_code = snr_dept start with dept_code in ( "+dept_code+" ))");
		/*	list.add(dept_code);
			islike.add(false);*/
		/*	}*/
			sqlbuf.append("ORDER BY planNO ");
		/*	if(StrUtil.isNotEmpty(pa))*/
			sql=sqlbuf.toString();
			
			String confStatus = StrUtil.getVal(paramMap.get("confStatus"));
			if("Y".equals(confStatus)){
				sql ="SELECT * FROM ("+sql+") A WHERE  exists (SELECT 1 FROM T_TRAD_AGENT_INFO_RELA R  where R.Insu_Plan_No=? and R.AGENT_INFO_ID= A.ID )";
				String planNo = StrUtil.getVal(paramMap.get("planNo"));
				if(StrUtil.isNotEmpty(planNo)){
					list.add(planNo);
					islike.add(false);
				}
			}else if("N".equals(confStatus)){
				sql ="SELECT * FROM ("+sql+") A WHERE not exists (SELECT 1 FROM T_TRAD_AGENT_INFO_RELA R  where R.Insu_Plan_No=? and R.AGENT_INFO_ID= A.ID )";
				String planNo = StrUtil.getVal(paramMap.get("planNo"));
				if(StrUtil.isNotEmpty(planNo)){
					list.add(planNo);
					islike.add(false);
				}
			}else{
				sql = " SELECT * FROM ("+sql+") A WHERE 1=1 ";
			}
			
			String branch =StrUtil.getVal(paramMap.get("branch"));
			if(StrUtil.isNotEmpty(branch)){
				sql = sql +" AND A.branch like ?";
				list.add(branch);
				islike.add(true);
			}
			String branchName =StrUtil.getVal(paramMap.get("branchName"));
			if(StrUtil.isNotEmpty(branchName)){
				sql = sql +" AND A.branch_name like ?";
				list.add(branchName);
				islike.add(true);
			}
			String deptId = StrUtil.getVal(paramMap.get("deptId"));
			if(StrUtil.isNotEmpty(deptId)){
				sql = sql +" AND A.DPT_CDE like ?";
				list.add(deptId);
				islike.add(true);
			}
			String deptName = StrUtil.getVal(paramMap.get("deptName"));
			if(StrUtil.isNotEmpty(deptName)){
				sql = sql + "AND A.dept_Cname like ?";
				list.add(deptName);
				islike.add(true);
			}
		/**/
			logger.debug("执行SQL：" + sql);
			
			pstmt = conn.prepareStatement("select count(*) from ("+sql+")");
			//处理模糊查找项
			for (int i = 0; i < list.size(); i++) {
				if(islike.get(i)){
					pstmt.setObject(i+1, "%"+list.get(i)+"%");
				}else{
					pstmt.setObject(i+1, list.get(i));
				}
				
			}
			rs = pstmt.executeQuery();
			rs.next();
			Long total = rs.getLong(1);
			page.setTotal(total);
			//查出分页
			SqlUtil sqlUtil=new	SqlUtil();
			String pagesql=sqlUtil.buildPageSqlForOracle(sql,page).toString();
			logger.debug("执行SQL："+pagesql);
			pstmt1 = conn.prepareStatement(pagesql);
			for (int i = 0; i < list.size(); i++) {
				if(islike.get(i)){
					pstmt1.setObject(i+1, "%"+list.get(i)+"%");
				}else{
					pstmt1.setObject(i+1, list.get(i));
				}
			}
			rs = pstmt1.executeQuery();
			List resultList = DBUtil.transRs2List(rs);
			
			page.setData(resultList);
		}finally{
			close(rs);
			close(pstmt);
			close(pstmt1);
			close(conn);
		}
		
		return page;
	}
	
	@Override
	public Page<Map<String, Object>> queryAgentInfoWithCombinedPageByCriteria(
			Page<Map<String, Object>> page) throws Exception {
		Connection conn = null;
		//查总条数
		PreparedStatement pstmt = null;
		//查分页
		PreparedStatement pstmt1 = null;
		ResultSet rs = null;
		try{
			conn = this.getConnection();
			StringBuffer sqlbuf=new StringBuffer();
			
			sqlbuf.append("SELECT T.ID,T.AGENT_TYPE,T1.CODE_NAME,T.USER_CODE,T3.USER_NAME, T.CHANNEL_CODE,")
					.append("T2.CHANNEL_NAME,T.SUB_CHANNEL_CODE,T.DPT_CDE,T.CHANNLE_CODE CHANNLECODE,")      
					.append("D1.CODE_NAME AS CHANNLECODEDES,T.CHANNLE_TYPE AS CHANNLETYPE,D2.CODE_NAME AS CHANNLETYPEDES,  ")    
					.append("T.NEW_BSNS_TYPE AS NEWBSNSTYPE,D3.CODE_NAME AS NEWBSNSTYPEDES,T.CATEGORY_CODE AS CATEGORYCODE,")       
					.append("D4.CODE_NAME AS CATEGORYCODEDES,T.AGENT_NO,T.PROTOCOL_NO,T.SERVICE_CODE,T.EMP_NO,T.CARD_APPLICANT,")       
					.append("T.TEAM_CODE,T.TEAM_NAME,T.C_BRKR_NME,T.C_OPR_CDE,T.SERVICE_NAME,T.EMP_NAME,T.Key1,T.Key2,T.Key3,T.Key4,T.Key5,T2.TRANS_TYPE")          
					.append(" FROM T_TRAD_AGENT_INFO T INNER JOIN T_GATEWAY_DICT T1 ON T.AGENT_TYPE = T1.CODE AND T1.CODE_TYPE = 'agent_type'")
					.append(" INNER JOIN T_GATEWAY_CHANNEL_INFO T2 ON T.CHANNEL_CODE = T2.CHANNEL_CODE AND T2.STATUS = '1'")
					.append(" LEFT  JOIN T_FACADE_USER T3 ON T.USER_CODE = T3.USER_CODE  AND T3.USER_TYPE IN ('3', '4')") 
					.append(" LEFT  JOIN t_gateway_dict d1 on d1.code_type ='belong_to_channel' and T.CHANNLE_CODE = d1.code")  
					.append(" LEFT  JOIN t_gateway_dict d2 on d2.code_type ='channel_type' and T.Channle_Type = d2.code")  
					.append(" LEFT  JOIN t_gateway_dict d3 on d3.code_type ='new_business_source' and T.New_Bsns_Type = d3.code")  
					.append(" LEFT  JOIN t_gateway_dict d4 on d4.code_type ='old_business_source' and T.Category_Code = d4.code")  
					.append(" left join T_TRAD_AGENT_INFO_RELA rela  on t.id=rela.agent_info_id   and  rela.insu_plan_no='"+page.getMap().get("planNo")+"'")
					.append(" where 1=1"); 
			String sql;
			List<String> list=new ArrayList<String>();
			List<Boolean> islike=new ArrayList<Boolean>();
			Map<String,Object> paramMap = page.getMap();
			
			String agentType =StrUtil.getVal(paramMap.get("agentType"));
			if(StrUtil.isNotEmpty(agentType)){
				sqlbuf.append(" and t.agent_type= ?");
				list.add(agentType);
				islike.add(false);
			}
			String key1 =StrUtil.getVal(paramMap.get("key1"));
			if(StrUtil.isNotEmpty(key1)){
				sqlbuf.append(" and t.key1= ?");
				list.add(key1);
				islike.add(false);
			}
			String key2 =StrUtil.getVal(paramMap.get("key2"));
			if(StrUtil.isNotEmpty(key2)){
				sqlbuf.append(" and t.key2= ?");
				list.add(key2);
				islike.add(false);
			}
			String key3 =StrUtil.getVal(paramMap.get("key3"));
			if(StrUtil.isNotEmpty(key3)){
				sqlbuf.append(" and t.key3= ?");
				list.add(key3);
				islike.add(false);
			}
			String key4 =StrUtil.getVal(paramMap.get("key4"));
			if(StrUtil.isNotEmpty(key4)){
				sqlbuf.append(" and t.key4= ?");
				list.add(key4);
				islike.add(false);
			}
			String key5 =StrUtil.getVal(paramMap.get("key5"));
			if(StrUtil.isNotEmpty(key5)){
				sqlbuf.append(" and t.key5= ?");
				list.add(key5);
				islike.add(false);
			}
			
			String channelCode =StrUtil.getVal(paramMap.get("partnerNo"));
			if(StrUtil.isNotEmpty(channelCode)){
				sqlbuf.append(" and t.channel_code = ?");
				list.add(channelCode);
				islike.add(false);
				sqlbuf.append(" and t.dpt_cde in (");
				sqlbuf.append("  select t1.dept_code from (");
				sqlbuf.append("  select t.dept_code, t.dept_cname from t_core_dept t connect by prior dept_code = snr_dept start with dept_code = (");
				sqlbuf.append("  select l.dept_code from T_GATEWAY_CHANNEL_INFO l where l.CHANNEL_CODE = ?)");
				sqlbuf.append("  ) t1  where length(t1.dept_code) = 8)");
				list.add(channelCode);
				islike.add(false);
			}
			sqlbuf.append("order by rela.insu_plan_no ");
			sql=sqlbuf.toString();
			
			String confStatus = StrUtil.getVal(paramMap.get("confStatus"));
			if("Y".equals(confStatus)){
				sql ="SELECT * FROM ("+sql+") A WHERE  exists (SELECT 1 FROM T_TRAD_AGENT_INFO_RELA R  where R.Insu_Plan_No=? and R.AGENT_INFO_ID= A.ID )";
				String planNo = StrUtil.getVal(paramMap.get("planNo"));
				if(StrUtil.isNotEmpty(planNo)){
					list.add(planNo);
					islike.add(false);
				}
			}else if("N".equals(confStatus)){
				sql ="SELECT * FROM ("+sql+") A WHERE not exists (SELECT 1 FROM T_TRAD_AGENT_INFO_RELA R  where R.Insu_Plan_No=? and R.AGENT_INFO_ID= A.ID )";
				String planNo = StrUtil.getVal(paramMap.get("planNo"));
				if(StrUtil.isNotEmpty(planNo)){
					list.add(planNo);
					islike.add(false);
				}
			}else{
				sql = " SELECT * FROM ("+sql+") A WHERE 1=1 ";
			}
			logger.debug("执行SQL：" + sql);
			
			pstmt = conn.prepareStatement("select count(*) from ("+sql+")");
			for (int i = 0; i < list.size(); i++) {
				if(islike.get(i)){
					pstmt.setObject(i+1, "%"+list.get(i)+"%");
				}else{
					pstmt.setObject(i+1, list.get(i));
				}
				
			}
			rs = pstmt.executeQuery();
			rs.next();
			Long total = rs.getLong(1);
			page.setTotal(total);
			//查出分页
			SqlUtil sqlUtil=new	SqlUtil();
			String pagesql=sqlUtil.buildPageSqlForOracle(sql,page).toString();
			logger.debug("执行SQL："+pagesql);
			pstmt1 = conn.prepareStatement(pagesql);
			for (int i = 0; i < list.size(); i++) {
				if(islike.get(i)){
					pstmt1.setObject(i+1, "%"+list.get(i)+"%");
				}else{
					pstmt1.setObject(i+1, list.get(i));
				}
			}
			rs = pstmt1.executeQuery();
			List resultList = DBUtil.transRs2List(rs);
			page.setData(resultList);
		}finally{
			close(rs);
			close(pstmt);
			close(pstmt1);
			close(conn);
		}
		
		return page;
	}
	
	@Override
	public List<TradAgentInfo> queryAgentInfoByMap(TradAgentInfo agent)
			throws Exception {
		return this.queryList("queryTradAgentInfoByMap",agent);
	}
	
	@Override
	public List<TradAgentInfo> queryAgentInByMap(Map<String, String> map)
			throws Exception {
		return this.queryList("queryTradAgentInByMap",map);
	}
	@Override
	public List<TradAgentInfo> searchExistUserCodeInfoFromDB(
			String channelCode, String str) throws AppException {
		Map<String,String> map = new HashMap<String,String>();
		map.put("channelCode", channelCode);
		map.put("userCodeStr", str);
		try {
			return this.queryList("queryExistUserCodesFromDB",map);
		} catch (SQLException e) {
			logger.error(e);
			throw new AppException("数据库应用忙，请稍后重试！");
		}
	}

	@Override
	public List<TradSaleAgent> queryTrandSaleAgent(String id) throws Exception {
		try {
			return this.queryList("queryTradSaleAgent", id);
		} catch (Exception e) {
			logger.error(e);
			throw new AppException("数据库应用忙，请稍后重试！");
		}
	}

	@Override
	public void deleteTrade(String id) throws Exception {
		this.delete("deleteTradSaleAgent", id);
	}

	@Override
	public boolean addTrade(List<TradSaleAgent> saleAgents) {
	     try {
			this.batchInsert("insertTradSaleAgent", saleAgents);
			return true;
		} catch (Exception e) {
			logger.error(e);
			return false;
		}
	}

	@Override
	public void deleteTrade1(List<String> list) throws Exception {
		this.delete("deleteTradSaleAgent1", list);
	}

	@Override
	public Map<String,String> queryTrade(String ids) throws Exception {
		Map<String,String> map=new HashMap<String, String>();
		Map<String,String> map1=new HashMap<String, String>();
		try {
			map1.put("ids", ids);
			List<TradAgentInfo> strs=this.queryList("queryExistSubBranchCodeInfoFromDB1", map1);
			for (TradAgentInfo tradAgentInfo : strs) {
				map.put(tradAgentInfo.getUserCode(), tradAgentInfo.getId()+"");
			}
		}catch (Exception e){
			logger.error(e);
		}
		return map;
	
	}
	
	@Override
	public Map<String,String> queryTrade1(String ids) throws Exception {
		Map<String,String> map=new HashMap<String, String>();
		Map<String,String> map1=new HashMap<String, String>();
		try {
			map1.put("ids", ids);
			List<TradAgentInfo> strs=this.queryList("queryExistSubBranchCodeInfoFromDB2", map1);
			for (TradAgentInfo tradAgentInfo : strs) {
				map.put(tradAgentInfo.getSubChannelCode(), tradAgentInfo.getId()+"");
			}
		}catch (Exception e){
			logger.error(e);
		}
		return map;
	
	}

	@Override
	public Map<String, String> queryTrade2(String ids,String planType) throws Exception {
		String sql="select agent.agent_info_id, count(agent.agent_info_id) count  from T_TRAD_PLAN_SALE_agent agent  where AGENT_INFO_ID  in ("+ids+") and plan_type= ? group by agent.agent_info_id";
		Map<String,String> map=new HashMap<String, String>();
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			conn = this.getConnection();
			logger.debug("excute :sql-->    "+sql.toString());
			pstmt = conn.prepareStatement(sql);
			pstmt.setObject(1, planType);
			rs=pstmt.executeQuery();
			while(rs.next()){
				map.put(rs.getString(1), rs.getString(2));	
			}
		}catch (Exception e){
			logger.error(e);
		}finally {
			close(pstmt);
			close(rs);
			close(conn);
		}
		return map;
	}
	@Override
	public Map<String,String> queryTrade3(String ids) throws Exception {
		Map<String,String> map=new HashMap<String, String>();
		Map<String,String> map1=new HashMap<String, String>();
		try {
			map1.put("ids", ids);
			List<TradAgentInfo> strs=this.queryList("queryUnionAgentByTrade", map1);
			for (TradAgentInfo tradAgentInfo : strs) {
				map.put(tradAgentInfo.getUserCode(), tradAgentInfo.getId()+"");
			}
		}catch (Exception e){
			logger.error(e);
		}
		return map;
	
	}
	@Override
	public void updateBachAgentInfo(List<TradAgentInfo> list)
			{
		 try {
			this.batchUpdate("updateTradAgentInfoNotNull", list);
		} catch (Exception e) {
			logger.error(e);
		}
	}

	@Override
	public List<TradAgentInfo> queryAgentInByMap1(String uniKey)
			 {
		try {
			return this.queryList("queryTradAgentInfoByMap1",uniKey);
		} catch (SQLException e) {
			logger.error(e);
			return null;
		}
	}
	@Override
	public Page<Map<String, Object>> queryAgentInfoWithCombinedPageByCriteria1(
			Page<Map<String, Object>> page) throws Exception {
		Connection conn = null;
		//查总条数
		PreparedStatement pstmt = null;
		//查分页
		PreparedStatement pstmt1 = null;
		ResultSet rs = null;
		try{
			conn = this.getConnection();
			StringBuffer sqlbuf=new StringBuffer();
			
			sqlbuf.append("SELECT T.ID,T.AGENT_TYPE,T1.CODE_NAME,T.USER_CODE,T3.USER_NAME, T.CHANNEL_CODE,")
					.append("T2.CHANNEL_NAME,T.SUB_CHANNEL_CODE,T.DPT_CDE,T.CHANNLE_CODE CHANNLECODE,")      
					.append("D1.CODE_NAME AS CHANNLECODEDES,T.CHANNLE_TYPE AS CHANNLETYPE,D2.CODE_NAME AS CHANNLETYPEDES,  ")    
					.append("T.NEW_BSNS_TYPE AS NEWBSNSTYPE,D3.CODE_NAME AS NEWBSNSTYPEDES,T.CATEGORY_CODE AS CATEGORYCODE,")       
					.append("D4.CODE_NAME AS CATEGORYCODEDES,T.AGENT_NO,T.PROTOCOL_NO,T.SERVICE_CODE,T.EMP_NO,T.CARD_APPLICANT,")       
					.append("T.TEAM_CODE,T.TEAM_NAME,T.C_BRKR_NME,T.C_OPR_CDE,T.SERVICE_NAME,T.EMP_NAME,T.Key1,T.Key2,T.Key3,T.Key4,T.Key5,T2.TRANS_TYPE")          
					.append(" FROM T_TRAD_AGENT_INFO T INNER JOIN T_GATEWAY_DICT T1 ON T.AGENT_TYPE = T1.CODE AND T1.CODE_TYPE = 'agent_type'")
					.append(" left JOIN T_GATEWAY_CHANNEL_INFO T2 ON T.CHANNEL_CODE = T2.CHANNEL_CODE AND T2.STATUS = '1'")
					.append(" LEFT  JOIN T_FACADE_USER T3 ON T.USER_CODE = T3.USER_CODE  AND T3.USER_TYPE IN ('3', '4')") 
					.append(" LEFT  JOIN t_gateway_dict d1 on d1.code_type ='belong_to_channel' and T.CHANNLE_CODE = d1.code")  
					.append(" LEFT  JOIN t_gateway_dict d2 on d2.code_type ='channel_type' and T.Channle_Type = d2.code")  
					.append(" LEFT  JOIN t_gateway_dict d3 on d3.code_type ='new_business_source' and T.New_Bsns_Type = d3.code")  
					.append(" LEFT  JOIN t_gateway_dict d4 on d4.code_type ='old_business_source' and T.Category_Code = d4.code")  
					.append(" left join T_TRAD_AGENT_INFO_RELA rela  on t.id=rela.agent_info_id   and  rela.insu_plan_no='"+page.getMap().get("planNo")+"'")
					.append(" where 1=1"); 
			String sql;
			List<String> list=new ArrayList<String>();
			List<Boolean> islike=new ArrayList<Boolean>();
			Map<String,Object> paramMap = page.getMap();
			
			String agentType =StrUtil.getVal(paramMap.get("agentType"));
			if(StrUtil.isNotEmpty(agentType)){
				sqlbuf.append(" and t.agent_type= ?");
				list.add(agentType);
				islike.add(false);
			}
			String key1 =StrUtil.getVal(paramMap.get("key1"));
			if(StrUtil.isNotEmpty(key1)){
				sqlbuf.append(" and t.key1 like  ? ");
				list.add("%"+key1+"%");
				islike.add(false);
			}
			String key2 =StrUtil.getVal(paramMap.get("key2"));
			if(StrUtil.isNotEmpty(key2)){
				sqlbuf.append(" and t.key2 like  ? ");
				list.add("%"+key2+"%");
				islike.add(false);
			}
			String key3 =StrUtil.getVal(paramMap.get("key3"));
			if(StrUtil.isNotEmpty(key3)){
				sqlbuf.append(" and t.key3 like ? ");
				list.add("%"+key3+"%");
				islike.add(false);
			}
			String key4 =StrUtil.getVal(paramMap.get("key4"));
			if(StrUtil.isNotEmpty(key4)){
				sqlbuf.append(" and t.key4 like ? ");
				list.add("%"+key4+"%");
				islike.add(false);
			}
			String key5 =StrUtil.getVal(paramMap.get("key5"));
			if(StrUtil.isNotEmpty(key5)){
				sqlbuf.append(" and t.key5 like ? ");
				list.add("%"+key5+"%");
				islike.add(false);
			}
			String unionType =StrUtil.getVal(paramMap.get("unionType"));
			if(StrUtil.isNotEmpty(unionType)){
				sqlbuf.append(" and t.union_Type= ?");
				list.add(unionType);
				islike.add(false);
			}
			String dept_code = StrUtil.getVal(paramMap.get("dept_code"));
			if(StrUtil.isNotEmpty(dept_code) && !"00".equals(dept_code)){
			  sqlbuf.append(" and t.dpt_cde like ?");
			  list.add(dept_code+"%");
			  islike.add(false);
			}else if(StrUtil.isNotEmpty(dept_code) && "00".equals(dept_code)){
				sqlbuf.append(" and t.dpt_cde in (select dept_code from t_core_dept t connect by prior dept_code = snr_dept start with dept_code in ( ? ))");
				list.add(dept_code);
				islike.add(false);
			}
/*			String channelCode =StrUtil.getVal(paramMap.get("partnerNo"));
			if(StrUtil.isNotEmpty(channelCode)){
				sqlbuf.append(" and t.channel_code = ?");
				list.add(channelCode);
				islike.add(false);
				sqlbuf.append(" and t.dpt_cde in (");
				sqlbuf.append("  select t1.dept_code from (");
				sqlbuf.append("  select t.dept_code, t.dept_cname from t_core_dept t connect by prior dept_code = snr_dept start with dept_code = (");
				sqlbuf.append("  select l.dept_code from T_GATEWAY_CHANNEL_INFO l where l.CHANNEL_CODE = ?)");
				sqlbuf.append("  ) t1  where length(t1.dept_code) = 8)");
				list.add(channelCode);
				islike.add(false);
			}*/
			sqlbuf.append("order by  rela.id, rela.insu_plan_no ");
			sql=sqlbuf.toString();
			
			String confStatus = StrUtil.getVal(paramMap.get("confStatus"));
			if("Y".equals(confStatus)){
				sql ="SELECT * FROM ("+sql+") A WHERE  exists (SELECT 1 FROM T_TRAD_AGENT_INFO_RELA R  where R.Insu_Plan_No=? and R.AGENT_INFO_ID= A.ID )";
				String planNo = StrUtil.getVal(paramMap.get("planNo"));
				if(StrUtil.isNotEmpty(planNo)){
					list.add(planNo);
					islike.add(false);
				}
			}else if("N".equals(confStatus)){
				sql ="SELECT * FROM ("+sql+") A WHERE not exists (SELECT 1 FROM T_TRAD_AGENT_INFO_RELA R  where R.Insu_Plan_No=? and R.AGENT_INFO_ID= A.ID )";
				String planNo = StrUtil.getVal(paramMap.get("planNo"));
				if(StrUtil.isNotEmpty(planNo)){
					list.add(planNo);
					islike.add(false);
				}
			}else{
				sql = " SELECT * FROM ("+sql+") A WHERE 1=1 ";
			}
			logger.debug("执行SQL：" + sql);
			
			pstmt = conn.prepareStatement("select count(*) from ("+sql+")");
			for (int i = 0; i < list.size(); i++) {
				if(islike.get(i)){
					pstmt.setObject(i+1, "%"+list.get(i)+"%");
				}else{
					pstmt.setObject(i+1, list.get(i));
				}
				
			}
			rs = pstmt.executeQuery();
			rs.next();
			Long total = rs.getLong(1);
			page.setTotal(total);
			//查出分页
			SqlUtil sqlUtil=new	SqlUtil();
			String pagesql=sqlUtil.buildPageSqlForOracle(sql,page).toString();
			logger.debug("执行SQL："+pagesql);
			pstmt1 = conn.prepareStatement(pagesql);
			for (int i = 0; i < list.size(); i++) {
				if(islike.get(i)){
					pstmt1.setObject(i+1, "%"+list.get(i)+"%");
				}else{
					pstmt1.setObject(i+1, list.get(i));
				}
			}
			rs = pstmt1.executeQuery();
			List resultList = DBUtil.transRs2List(rs);
			page.setData(resultList);
		}finally{
			close(rs);
			close(pstmt);
			close(pstmt1);
			close(conn);
		}
		
		return page;
	}

	@Override
	public boolean addTradeSale(List<TradSaleAgent> saleAgents,String agentType)  {
		try {
			this.batchInsert("insertTradSaleAgent"+agentType, saleAgents);
			return true;
		} catch (Exception e) {
			logger.info(e);
			return false;
		}
	}
	@Override
	public boolean deleteCommPlanRate(Map<String, Object> map)
			throws Exception {
		return this.delete("delCommPlanRate", map);
	}

	@Override
	public boolean addCommPlanRate(Map<String, Object> map) throws Exception {
		return this.add("addCommPlanRate", map);
	}

	@Override
	public boolean deleteCommPlanRate1(Map<String, Object> map)
			throws Exception {
		return this.delete("delCommPlanRate1", map);
	}
	@Override
	public List<TradAgentInfo> isExtTradPlanSale(Map<String, Object> map) throws Exception {
		return this.queryList("isExtTradPlanSale", map);
	}

	@Override
	public List<TradAgentInfo> isExtZonTradPlanSale4(Map<String, Object> map)
			throws Exception {
		return this.queryList("isExtTradZonPlanSale", map);
	}

	@Override
	public List<TradAgentInfo> isExtZonTradPlanSale5(Map<String, Object> map)
			throws Exception {
		return this.queryList("isExtTradZonPlanSale5", map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Page<TradAgentInfo> selectCarAgentInfo(Page<TradAgentInfo> page)
			throws Exception {
		int count = selectCarAgentInfoCount(page.getMap());
		page.setTotal(count);
		List<TradAgentInfo> list = (List<TradAgentInfo>)this.queryList("selectCarAgentInfo", page.getMap());
		page.setData(list);
		return page;
	}

	@Override
	public int selectCarAgentInfoCount(Map<String, Object> map)
			throws Exception {
		return (Integer) this.query("selectCarAgentInfoCount",map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TradAgentInfo> selectAddCarAgentInfo(Map<String, String> map)
			throws Exception {
		return (List<TradAgentInfo>)this.queryList("selectAddCarAgentInfo", map);
	}

	@Override
	public TradAgentInfo queryAgentInfoByProductType(TradAgentInfo agentInfo) throws Exception {
		return (TradAgentInfo) this.query("queryAgentInfoByProductType", agentInfo);
	}

}
